<template>
    <view class="tabs-box">
        <view v-for="item in list" :v-key="item.id" class="tabs-item" :class="{ 'active': index == item.id }"
            @click="changeTabs(item)">{{ item.name }}</view>
    </view>
</template>
<script lang="ts" setup>
import { onMounted, ref, onUnmounted, } from 'vue';
type item = {
    id: number,
    name: string
}
const emit = defineEmits(['changeTabs'])
const props = defineProps({
    list: { type: Array<item>, default: [] },
    current: {
        type: Number,
        default: 1
    }
})
let index = ref<number>(props.current)

function changeTabs(item: item) {
    index.value = item.id
    emit('changeTabs', index.value);
}

</script>

<style lang="scss" scoped>
.tabs-box {
    display: flex;
    height: 100rpx;
    line-height: 100rpx;
    color: #999;
    font-size: 30rpx;
    padding: 0 14rpx;
    overflow-x: scroll;
    white-space: nowrap;

    .tabs-item {
        margin-right: 40rpx;

        &:last-child {
            margin-right: 0;
        }

        &.active {
            font-size: 32rpx;
            color: #333;
            font-family: PingFang SC Bold;
            position: relative;

            &::after {
                content: '';
                display: inline-block;
                position: absolute;
                width: 40rpx;
                height: 8rpx;
                background-color: #FF544F;
                border-radius: 0.15625rem;
                left: 50%;
                bottom: 10px;
                transform: translate(-50%);
            }
        }
    }
}
</style>